-
-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Fix MSVC warning for potential mod by 0 (C4724) #106634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
I'm adding static casts to |
|
Sorry, I didn't read the return type closely enough. I'm used to container size types always being unsigned e.g. Either way, the original usage of |
We don't usually use explicit static casts in such cases. Our consensus is that it makes code harder to read and doesn't add much value. |
Should I remove the casts or just leave them? |
I would just use |
Looks good! Could you squash the commits? See PR workflow for instructions. |
With
dev_mode=yes
, MSVC warns that some modulo expressions may bex % 0
and refuses to compile.By assigning the size variables to local variables, the compiler knows
size > 0
if the loop bodies are entered. Without the local variable, it's technically possible forsize()
to become zero after entering the body.https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4724?view=msvc-170